#!/bin/bash
##
# File Name: add_dev.sh
# Author: 
# Created Time: 2018-11-13
# Describe: 添加新的内网域名解析

trap "exit 1" INT
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export LANG=en_US.UTF-8

script=`basename $0`
config_dir="/etc/unbound/local.d/project"



echo_usage () {
echo "Usage: $script <new_project>"
echo "Example:"
echo "$script mantianfei"
}



[ $# -eq 0 ] && {
    echo_usage
    exit 1
} || new_domain="$1".dev.com

ls ${config_dir} |grep -q "${new_domain}" && {
echo "Error: the domain ${new_domain} already exists"
exit 1
}

echo "\
local-data: \"$new_domain 3600 IN A 192.168.0.119\"
local-data: \"open.${new_domain} 3600 IN A 192.168.0.119\"
local-data: \"pf.${new_domain} 3600 IN A 192.168.0.119\"" > ${config_dir}/${new_domain}.conf

echo "OK: add new domain ${new_domain} complete, please restart unbound, systemctl restart unbound"
exit 0


